package com.example.ipcdemo.service;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Log;

import androidx.annotation.NonNull;

import com.example.ipcdemo.IRemoteService;
import com.example.ipcdemo.TaskInfo;
import com.example.ipcdemo.aidl.IRemoteImpl;

import java.util.ArrayList;
import java.util.List;

public class RemoteService extends Service {
    private static final String TAG = "RemoteService";

    public RemoteService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
       return mBinder;
    }

    //AIDL 的服务，
    IRemoteImpl mBinder = new IRemoteImpl() {
        @Override
        public int add(int num1, int num2) throws RemoteException {
            /**
             * 这里为具体的实现方法，比如直接返回两数之和
             */
            Log.d(TAG, "zsr add: 接收到客户端传递的两个数字： "+num1+" "+num2);
            return (num1 + num2);
        }

        @Override
        public TaskInfo addTask(TaskInfo info) throws RemoteException {
            Log.d("zsr", "收到客户端的信息: "+info);
            info.id = 0;
            info.progress = 50;
           // mHandler.sendEmptyMessage(1);
           // mTaskInfo = info;
            return info;
        }
    };






    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
